/////////////////////////////////////////////////////////////////////////////
// Original code from libhdfs3. Copyright (c) 2013 - 2014, Pivotal Inc.
// All rights reserved. Author: Zhanwei Wang
/////////////////////////////////////////////////////////////////////////////
//  Modifications by Kumo Inc.
// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//



#ifndef _HDFS_LIBHDFS3_CLIENT_PACKETHEADER_H_
#define _HDFS_LIBHDFS3_CLIENT_PACKETHEADER_H_

#include <kmhdfs/proto/datatransfer.pb.h>

namespace Hdfs {
namespace Internal {

class PacketHeader {
public:
    PacketHeader();
    PacketHeader(int packetLen, int64_t offsetInBlock, int64_t seqno,
                 bool lastPacketInBlock, int dataLen);
    bool isLastPacketInBlock();
    bool sanityCheck(int64_t lastSeqNo);
    int getDataLen();
    int getPacketLen();
    int64_t getOffsetInBlock();
    int64_t getSeqno();
    void readFields(const char * buf, size_t size);
    /**
     * Write the header into the buffer.
     * This requires that PKT_HEADER_LEN bytes are available.
     */
    void writeInBuffer(char * buf, size_t size);

public:
    static int GetPkgHeaderSize();
    static int CalcPkgHeaderSize();

private:
    static int PkgHeaderSize;
private:
    int32_t packetLen;
    PacketHeaderProto proto;
};

}
}

#endif /* _HDFS_LIBHDFS3_CLIENT_PACKETHEADER_H_ */
